package cn.hxth.cloud.datasync.rabbitmq;

import cn.hxth.cloud.api.common.constant.ProcedureStatus;
import cn.hxth.cloud.api.domain.ProductionOrder;
import cn.hxth.cloud.api.rabbitmq.AbstractRabbitMQHandler;
import cn.hxth.cloud.api.rabbitmq.RabbitMQSender;
import cn.hxth.cloud.service.service.InventoryService;
import cn.hxth.cloud.service.service.OrderService;
import cn.hxth.cloud.service.service.ProductionService;
import cn.hxth.cloud.service.service.WmsService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
@RabbitListener(queues = "data-change-queue-production")
public class DataChangeQueueReceiver extends AbstractRabbitMQHandler {

    @Autowired
    private OrderService orderService;
    @Autowired
    private InventoryService inventoryService;
    @Autowired
    private ProductionService productionService;
    @Autowired
    private WmsService wmsService;
    /*@Resource
    private WmsFacadeService wmsFacadeService ;*/
   @Autowired
    public DataChangeQueueReceiver(RabbitMQSender rabbitMQSender) {
        super(rabbitMQSender);
        super.setLogger(DataChangeQueueReceiver.class);
    }


    private Boolean processInsertProductionOrder(JSONObject jsonObject, String jsonStr) {
        List<ProductionOrder> productionOrders = JSONObject.parseArray(jsonStr, ProductionOrder.class);
        ProductionOrder[] array = new ProductionOrder[productionOrders.size()];
        ProductionOrder[] productionOrdersArray = productionOrders.toArray(array);
        String mid = jsonObject.getString("mid");
        Boolean flag = this.productionService.insertProductionOrder(productionOrdersArray, mid);
        return flag;
    }

    private Boolean processUpdateProductionStatus(JSONObject jsonObject, String jsonData) throws Exception {
        ProductionOrder productionOrder = JSONObject.parseObject(jsonData, ProductionOrder.class);
        Boolean flag = this.productionService.updateStatus(productionOrder);
        /*if(flag && ProcedureStatus.COMMITTED.equals(productionOrder)){

        }*/
        return  flag ;


    }


}
